﻿package {
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.utils.setInterval;
	
	import adobe.utils.MMExecute;
	
	import br.com.stimuli.string.printf;
	
	import fl.controls.Button;
	import fl.controls.TextInput;	

	/**
	 * @author colin
	 */
	public class ClassNameToolsPanel extends MovieClip {
		private var filePath:String;
		private var scriptFile:String;

		public var txfClass:TextInput;

		public var btnGetClass:Button;
		public var btnSetClass:Button;
		public var txtScriptVersion:TextField;
		public var txtGetClass:TextField;
		
		public function ClassNameToolsPanel(){
			this.addEventListener(Event.ADDED_TO_STAGE, onStage,false,0,true);
		}

		public function onStage(e:Event):void{
			filePath  = MMExecute("fl.configURI")+ "Commands/";
			scriptFile= filePath+"classNameTools.jsfl";

			btnGetClass.addEventListener(MouseEvent.CLICK, getClass );
			btnSetClass.addEventListener(MouseEvent.CLICK, setClass );
			txfClass.addEventListener(FocusEvent.FOCUS_IN, copyClass);

			this.addEventListener(MouseEvent.MOUSE_OVER, update);
			this.stage.align = "TL";
			setInterval(update,1000);
			update();
		}
		
		private function update(...e):void{
			txtScriptVersion.text = "- AS"+MMExecute(printf("fl.runScript('%s','%s')",scriptFile,'getVersion'));
			getClass();
		}
		
		private function setClass(...e):void{
			MMExecute(printf("fl.runScript('%s','%s','%s')",scriptFile,'setClass',txfClass.text));
			txfClass.text="";
		}
		
		private function getClass(...e):void{
			txtGetClass.text = MMExecute(printf("fl.runScript('%s','%s')",scriptFile,'getClass'));
		}
		
		private function copyClass(...e):void{
			if(txtGetClass.text.indexOf("MSG:")!=-1)return;
			
			txfClass.text = txtGetClass.text;
		}
	}
}
